package com.ysqcould.web.controller.allocation;


import com.ysqcould.allocation.domain.Dues;
import com.ysqcould.allocation.domain.WxRole;
import com.ysqcould.allocation.service.IDuesService;
import com.ysqcould.allocation.service.IWxRoleService;
import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会费Controller
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/allocation/dues")
public class DuesController extends BaseController
{
    @Autowired
    private IDuesService duesService;
    @Autowired
    private IWxRoleService wxRoleService;


    /**
     * 查询会费列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:dues:list')")
    @GetMapping("/list")
    public TableDataInfo list(Dues dues)
    {
        startPage();
        List<Dues> list = duesService.selectDuesList(dues);
        return getDataTable(list);
    }

    /**
     * 导出会费列表
     */
    @PreAuthorize("@ss.hasPermi('allocation:dues:export')")
    @Log(title = "会费", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Dues dues)
    {
        List<Dues> list = duesService.selectDuesList(dues);
        ExcelUtil<Dues> util = new ExcelUtil<Dues>(Dues.class);
        util.exportExcel(response, list, "会费数据");
    }

    /**
     * 获取角色列表
     * @return
     */
    @GetMapping("/getRoles")
    public AjaxResult getRoles()
    {
        final Long asId = getUserId();
        WxRole role=new WxRole();
        role.setAsId(asId);
        return AjaxResult.success(wxRoleService.selectWxRoleList(role));
    }

    /**
     * 获取会费详细信息
     */
    @PreAuthorize("@ss.hasPermi('allocation:dues:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(duesService.selectDuesById(id));
    }

    /**
     * 新增会费
     */
    @PreAuthorize("@ss.hasPermi('allocation:dues:add')")
    @Log(title = "会费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Dues dues)
    {
        dues.setAsId(getUserId());
        return toAjax(duesService.insertDues(dues));
    }

    /**
     * 修改会费
     */
    @PreAuthorize("@ss.hasPermi('allocation:dues:edit')")
    @Log(title = "会费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Dues dues)
    {
        return toAjax(duesService.updateDues(dues));
    }

    /**
     * 删除会费
     */
    @PreAuthorize("@ss.hasPermi('allocation:dues:remove')")
    @Log(title = "会费", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(duesService.deleteDuesByIds(ids));
    }

    /**
     * 状态修改
     */
    @Log(title = "通信录", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody Dues dues)
    {
        return toAjax(duesService.updateStatus(dues));
    }
}
